/**
Application: top bar of the website
Author:chilei 
Date:2012/11/28
*/
Ext.QuickTips.init();
//这种继承的方法，就是没办法嵌套panel，不清楚为什么
/*
Ext.namespace("Ext.clNameSpace");
//user define class
Ext.clNameSpace.clTopBar = Ext.extend(Ext.Panel,{
	title:'yes',
	height:100,
	html:'Test',
	
	items:[	
		new Ext.Panel({
			html:'tt',
			region:'north'
			
		})
	]
	
});
//regedit this UI control
Ext.reg("cltopbar",Ext.clNameSpace.clTopBar);
*/

Ext.namespace("Ext.clNameSpace");
Ext.clNameSpace.topBar = function(config){
	config = config||{};
	var searchBtn = new Ext.Button({
		
		text:'搜索',
		pressed:true,
		height:100,
		listeners:{
			"click":function(){
				var searchname = Ext.getCmp("searchfile").getValue();
				var filter = /^[#$&\*]+/
				if(filter.test(searchname)){
					alert("含有非法字符");
					return;
				}
				
				var items = Ext.getCmp("main_content").items;
       			if(items != null){
	       			for (var i = 0; i < items.getCount(); i=i+1)   
	              		Ext.getCmp("main_content").remove(items.get(i)); 
	       		}
	            Ext.getCmp("main_content").add(new Ext.clNameSpace.searchmainPanel({
	    		}));	
	    		Ext.getCmp("main_content").render();
	    		Ext.getCmp("main_content").doLayout();
	    		var content_panel = Ext.getCmp("highfilelist");
	    		content_panel.getStore().proxy.url = "login/searchallfile.action?searchname="+encodeURI(encodeURI(searchname))+"&type="+radiochecked;
	    		content_panel.getStore().reload();
			}
		}
	});
	//搜索
	function searchEnter(){
	
				var searchname = Ext.getCmp("searchfile").getValue();
				var filter = /^[#$&\*]+/
				if(filter.test(searchname)){
					alert("含有非法字符");
					return;
				}
				
				var items = Ext.getCmp("main_content").items;
       			if(items != null){
	       			for (var i = 0; i < items.getCount(); i=i+1)   
	              		Ext.getCmp("main_content").remove(items.get(i)); 
	       		}
	            Ext.getCmp("main_content").add(new Ext.clNameSpace.searchmainPanel({
	    		}));	
	    		Ext.getCmp("main_content").render();
	    		Ext.getCmp("main_content").doLayout();
	    		var content_panel = Ext.getCmp("highfilelist");
	    		content_panel.getStore().proxy.url = "login/searchallfile.action?searchname="+encodeURI(encodeURI(searchname))+"&type="+radiochecked;
	    		content_panel.getStore().reload();
	}
	
	function downloadnew(h,g,e,j,f){
    	var filevalue = e.data.title;
              
        return "<input type='button' onclick='downloadFile()' value='下载'>";
    }
	var radiochecked = 0;
	
	var searchForm = new Ext.Panel({
		layout:'table',
		border:false,
		layoutConfig:{
			columns:6
		},
		width:690,
		height:100,
		defaultType:'textfield',
		items:[
		{xtype:'label',text:'  ',height:20,colspan:6},
		{xtype:'label',text:'  ',height:20,width:200},
		{fieldLabel:'搜索条件',name:'searchfile',id:'searchfile',width:400,colspan:4,listeners:{'specialkey' :function(field, e) {
                                        if (e.getKey() == Ext.EventObject.ENTER) {
                                        	searchEnter();
                                        }}
                                    }},
		searchBtn,
		{xtype:'label',text:'  ',height:20,width:200},
		{ xtype:"radio",checked:true,name:"filetype",boxLabel:"全部",listeners:{check:function(checkbox, checked){if(checked){radiochecked=0;}}}},
		{ xtype:"radio",checked:false,name:"filetype",boxLabel:"word",listeners:{check:function(checkbox, checked){if(checked){radiochecked=1;}}}},
		{ xtype:"radio",checked:false,name:"filetype",boxLabel:"excel",listeners:{check:function(checkbox, checked){if(checked){radiochecked=2;}}}},
		{ xtype:"radio",checked:false,name:"filetype",boxLabel:"ppt",listeners:{check:function(checkbox, checked){if(checked){radiochecked=3;}}}},
		{ xtype:"radio",checked:false,name:"filetype",boxLabel:"图片",listeners:{check:function(checkbox, checked){if(checked){radiochecked=4;}}}}
		]
	});
	
	var innerPanel = new Ext.Panel({
		border:false,
		width:200,
		height:100,
		html:'<img src="../images/firefox-gray.jpg">'
		
	});
	var _config = Ext.apply({
		layout:'column',
		width:1020,
		heigth:100,
		items:[innerPanel,searchForm]
	},config);
	
	Ext.clNameSpace.topBar.superclass.constructor.call(this,_config);
	
};
Ext.extend(Ext.clNameSpace.topBar,Ext.Panel,{});


